<template>
	<view class="pullLiver">
		拉流
		<!-- <video src="rtmp://172.16.201.181:1935/live/test1" controls></video> -->
		推流
		<button type="default" @click="changeType" style="position: fixed;top: 999;left: 0;top: 0;">切换</button>
	</view>
</template>

<script>
	export default{
		name: 'pullLiver',
		data(){
			return{
				pusher: null,
				styles: {
					url: 'rtmp://172.16.201.181:1935/live/rfBd56ti2SMtYvSgD5xAV0YU99zampta7Z7S575KLkIZ9PYk',
					top: '20px',
					left: '0px',
					width: '100%',
					height: '300px',
					position: 'static',
					mode: 'HD',
					aspect: '16:9',
					muted: false,
				}
			}
		},
		onLoad() {
			var min = 'min-bitrate';
			var max ='max-bitrate';
			this.styles[min]=2500;
			this.styles[max]=3000;
			this.init()
		},
		methods:{
			changeType(){
				this.pusher.switchCamera();
				this.pusher.start()
			},
			init(){
				const currentWebview = this.$mp.page.$getAppWebview()
				
				var pusher = plus.video.createLivePusher("pusher", this.styles);

				pusher.addEventListener('statechange', function(e) {
					console.log(e,'statechangestatechangestatechangestatechange')
				}, false)
				pusher.addEventListener('netstatus', function(e) {
					console.log(e,'netstatusnetstatusnetstatus')
				}, false)
				pusher.addEventListener('error', function(e) {
					console.log(e,'errorerrorerror')
				}, false)
				currentWebview.append(pusher);
				
				pusher.start()
				
				this.pusher = pusher
				
				var puller = plus.video.createVideoPlayer("", {
					src: 'rtmp://172.16.201.181:1935/live/test1',
					top: '350px',
					left: '0px',
					width: '100%',
					height: '300px',
					position: 'static'
				});
				
				currentWebview.append(puller);
			}
		}
	}
</script>

<style>
</style>
